package com.ai.bitcoin.input;


import com.ai.bitcoin.jpa.entity.BccUser;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;

public abstract class RequestHepler {
	private static final Logger logger = LoggerFactory.getLogger(RequestHepler.class);
	
	private static final String TYPE = "type";
	private static final String  OFFSET= "offset";
	private static final String  FETCHSize= "fetchSize";

	private static final String USER = "user";
	
	public static GeneralRequest processRequest(HttpServletRequest request) {
		
		// support data,clientInfo param
		GeneralRequest generalRequest = new GeneralRequest();
		
		String type = request.getParameter(TYPE);
		String offset = request.getParameter(OFFSET);
		if(StringUtils.isNotBlank(offset)){
			generalRequest.setOffset(Integer.parseInt(offset));
		}
		String fetchSize = request.getParameter(FETCHSize);
		if(StringUtils.isNotBlank(fetchSize)){
			generalRequest.setFetchSize(Integer.parseInt(fetchSize));
		}
		generalRequest.setType(type);


		BccUser user = (BccUser) request.getAttribute(USER);
		if(user != null) {
			generalRequest.setUser(user);
		}

		return generalRequest;
	}

}
